const { fetch } = require('../../utils/util.js')
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    markers: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const _this = this;
    fetch({
      url: 'api/zhuang/GetmarkersList',
      params: {lv:1},
      success: (res) => {
        console.log('地图：')
        console.log(res)
        if (res instanceof Array) {
          let markers = [];
          for (let i = 0; i < res.length; i++) {
            let marker = _this.createMarker(res[i]);
            markers.push(marker)
          }
          _this.setData({
            markers: markers
          })
        }
      }
    });
  },

  /**
   * 创建marker对象
   */
  createMarker(item) {
    let marker = {
      ...item,
      id: item.aid || 0,
      iconPath: "../../assets/icons/dp-gl.png"
    };
    return marker;
  },

  /**
   * 点击marker
   */
  markertap: function (e) {
    app.pageTo(`/pages/mapContent/mapContent?id=${e.markerId}`)
  }, 
})